package com.house.data;


import com.house.enums.ResultEnum;

//统一返回实体类
public class Result<T> {
    private Integer code;
    private String message;
    private T data;

    public static Result ok() {
        Result result = new Result(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage());
        return result;
    }

    public static Result refundOK() {
        Result result = new Result(ResultEnum.REFUND_SUCCESS.getCode(), ResultEnum.REFUND_SUCCESS.getMessage());
        return result;
    }
    public static Result refundError() {
        Result result = new Result(ResultEnum.REFUND_ERROR.getCode(), ResultEnum.REFUND_ERROR.getMessage());
        return result;
    }


    public static Result error() {
        Result result = new Result(ResultEnum.ERROR.getCode(), ResultEnum.ERROR.getMessage());
        return result;
    }

    public static Result fallback() {
        Result result = new Result(ResultEnum.TOO_MANY_REQUEST.getCode(), ResultEnum.TOO_MANY_REQUEST.getMessage());
        return result;
    }

    public static Result error(ResultEnum em) {
        Result result = new Result(em.getCode(),em.getMessage());
        return result;
    }

    public static Result response(ResultEnum em){
        Result result = new Result(em.getCode(),em.getMessage());
        return result;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Result(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result() {
    }



    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public Result setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result setData(T data) {
        this.data = data;
        return this;
    }
}
